$(function(){
    // 消火栓 
    // 消火栓 历史详情
    $(".fireHydrant-trigger").on("click", function(e){
        event.preventDefault();
        console.log("消火栓历史详情");
        $(".fireHydrantHisDetails-pop").addClass("is-visible3");
        // 时间选择器
        $('.time').clockTimePicker();
        
        fireHydrantHisPressure();
    })

    // 消火栓 历史详情 关闭窗口
    $(".fireHydrantHisDetails-pop").on("click", function (event) {
        if (
        $(event.target).is(".cd-popup-close") ||
        $(event.target).is(".fireHydrantHisDetails-pop")
        ) {
        event.preventDefault();
        $(this).removeClass("is-visible3");
        }
    });

    // 历史消火栓 压力
    function fireHydrantHisPressure(){
        $.ajax({
            url: "/threeColor/getThreeColorWarningProportion",
            type: 'GET',
            // async: false, 
            success: function (result) {      
                console.log(result.data);    
                // 初始化 实例
                var fireHydrantHisPressure = echarts.init(document.getElementById("fireHydrantHisPressure"));
                option = {
                    tooltip: {
                        trigger: 'axis'
                    },
                    legend: {
                        left: 250,
                        top: 210,
                        icon: "circle",
                        textStyle: {
                            color: "#fff",
                            padding: [0 ,5 ,0 ,0 ]
                        },
                        data:['历史消火栓压力','历史水位']
                    },
                    grid: {
                        x: '12%',
                        x2: 40,
                        y: 30,
                        y2: 30,
                        containLabel: true
                    },
                    xAxis:  {
                        type: 'category',
                        boundaryGap: true,
                        axisLine: {
                          lineStyle: {
                              color: "#fff"
                          }  
                        },
                        data: [1,2,3,4,5,6,7]
                    },
                    yAxis:[ 
                        {
                            name: '历史消火栓压力(Pa)',
                            type: 'value',
                            max: 40,
                            axisLine: {
                              lineStyle: {
                                  color: "#fff"
                              }  
                            },
                        },
                        {
                            name: '历史水位(m)',
                            type: 'value',
                            max: 80,
                            axisLine: {
                              lineStyle: {
                                  color: "#fff"
                              }  
                            },
                        }
                    ],
                    series: [
                         {
                            name:'历史消火栓压力',
                            color: '#3bfffd',
                            type:'line',
                            symbol: 'circle' ,
                            symbolSize: 8,
                            data:[20, 22, 35, 22, 28, 23, 20],
                            markLine: {
                                symbol: 'circle',
                                label: {
                                    show: false
                                },
                                lineStyle: {
                                   color: "#6ed83b",  
                                   type: 'dashed',
                                   width: 2
                                },
                                data: [
                                    {
                                        name: 'Y 轴值为 30 的水平线', 
                                        yAxis: 30
                                    }
                                ]
                            }
                        },
                        {
                            name:'历史水位',
                            color: '#ffec47',
                            type:'line',
                            symbol: 'circle' ,
                            symbolSize: 8,
                            yAxisIndex: 1,
                            data:[30, 35, 42, 36, 38, 34, 30],
                            markLine: {
                                symbol: 'circle',
                                label: {
                                    show: false
                                },
                                lineStyle: {
                                   color: "#bb662e",  
                                   type: 'dashed',
                                   width: 2
                                },
                                data: [
                                    {
                                        name: 'Y 轴值为 80 的水平线', 
                                        yAxis: 80
                                    }
                                ]
                            }
                        },
                    ]
                };
                
                   
                // 使用制定的配置项和数据显示图表
                fireHydrantHisPressure.setOption(option);
            }
        });   
    }

    // 微型消防站 查看详情页面显示
    // $(".detailFireStation-pop").addClass("is-visible3");

    // 微型消防站 查看详情页面 关闭窗口
    $(".detailFireStation-pop").on("click", function (event) {
        if (
        $(event.target).is(".cd-popup-close") ||
        $(event.target).is(".detailFireStation-pop")
        ) {
        event.preventDefault();
        $(this).removeClass("is-visible3");
        }
    });

    // 消火栓查看详情
    // $(".fireHydrantDetails-pop").addClass("is-visible3");

    // 消火栓查看详情 关闭窗口
    $(".fireHydrantDetails-pop").on("click", function (event) {
        if (
        $(event.target).is(".cd-popup-close") ||
        $(event.target).is(".fireHydrantDetails-pop")
        ) {
        event.preventDefault();
        $(this).removeClass("is-visible3");
        }
    });
});

  // 地图上的查看详情点击查看详情
  function fireHydrantSeeDetailsFunc1(){
    $("body .fireHydrantSeeDetails").on("click", function (event) {
      event.preventDefault();
      var $this = $(this);
      console.log(this);
      $('.fireHydrantDetails-pop').addClass('is-visible3');
      $.ajax({
        url:'/deviceStatus/get/code?deviceCode='+$this.attr('no'),
        success:function(res){
          console.log(res);
          var deviceid = res.data[0][0].id;
          var deviceName = res.data[0][0].deviceName;
          var usestatus = res.data[0][0].usestatus;
          var deviceTypeName = res.data[0][0].deviceType.deviceTypeName;
          var deviceTypeId = res.data[0][0].deviceType.deviceTypeId;
          var devCode = res.data[0][0].devCode;
          var address = res.data[0][0].address;
          var fixedPlace = res.data[0][0].fixedPlace;
          var latitude = res.data[0][0].latitude;
          var longitude = res.data[0][0].longitude;
          var installationDate = res.data[0][0].installationDate;
          var deadline = res.data[0][0].deadline;
          var linkMain1 = res.data[0][0].linkMain1;
          var linkMain2 = res.data[0][0].linkMain2;
          var linkMain3 = res.data[0][0].linkMain3;
          var linkPhone1 = res.data[0][0].linkPhone1;
          var linkPhone2 = res.data[0][0].linkPhone2;
          var linkPhone3 = res.data[0][0].linkPhone3;
          var remark = res.data[0][0].remark;
          var fireCount = res.data[0][0].fireCount;
  
          var chargingInterfaceNumber = res.data[0][0].chargingInterfaceNumber;
          var manufacturer = res.data[0][0].manufacturer;
          var waterGage = res.data[0][0].waterGage;
          var waterLevel = res.data[0][0].waterLevel;
          var urrentMarginThreshold = res.data[0][0].urrentMarginThreshold;
          var temperatureThreshold = res.data[0][0].temperatureThreshold;
          var cameraUrl = res.data[0][0].cameraUrl;
          var streamServer = res.data[0][0].streamServer;
          var orgName = res.data[0][0].organization.orgName;
          var photoUrl = res.data[0][0].photoUrl;
          installationDate = installationDate ? moment(installationDate).format("YYYY-MM-DD") : '';
          deadline = deadline ? moment(deadline).format("YYYY-MM-DD") : '';
          if(usestatus==0){
            usestatus='禁用';
          }else if(usestatus==1){
            usestatus='启用';
          }
          $('#fireHydrantDetailsForm .fireHydrantDetailsName').val(deviceName);
          $('#fireHydrantDetailsForm .fireHydrantDetailsUse').val(usestatus);
          $('#fireHydrantDetailsForm .fireHydrantDetailsDeviceType').val(deviceTypeName);
          $('#fireHydrantDetailsForm .fireHydrantDetailsDevCode').val(devCode);
          $('#fireHydrantDetailsForm .fireHydrantDetailsAddress').val(address);
          $('#fireHydrantDetailsForm .fireHydrantDetailsFixedPlace').val(fixedPlace);
          $('#fireHydrantDetailsForm .fireHydrantDetailsLongitude').val(longitude);
          $('#fireHydrantDetailsForm .fireHydrantDetailsLatitude').val(latitude);
          $('#fireHydrantDetailsForm .fireHydrantDetailsInsDate').val(installationDate);
          $('#fireHydrantDetailsForm .fireHydrantDetailsDeadline').val(deadline);
          $('#fireHydrantDetailsForm .fireHydrantDetailsContact').val(linkMain1);
          $('#fireHydrantDetailsForm .fireHydrantDetailsRemark').val(remark);
          $('#fireHydrantDetailsForm .fireHydrantDetailsOrgList').val(orgName);

        }
      })
    });
  
  }